﻿<%@ WebHandler Language="C#" Class="Approved_Item" %>

using System;
using System.Web;
using System.Data;
using System.Data.Common;

/// <summary>
/// 本ASHX文件主要使用于评论的审核
/// </summary>
public class Approved_Item : IHttpHandler{
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        /* 管理员验证 */
        if (!Admins.IsLogin(true))
            Utils.ShowEnd(context, "-2");

        /* 接受ID */
        Int32 item_id = Convert.ToInt32(context.Request.Params["item_id"].ToString());
        Int32 item_typ = Convert.ToInt32(context.Request.Params["item_typ"].ToString());
        Int32 item_status = Convert.ToInt32(context.Request.Params["item_status"].ToString());

        /* 数据验证码 */
        Verification verifiacation = new Verification();
        if (!verifiacation.VerificationMinMaxValue(item_id, 1, 65000))
            Utils.ShowEnd(context, -1);
        if (!verifiacation.VerificationMinMaxValue(item_typ, 1, 256))
            Utils.ShowEnd(context, -1);
        if (!verifiacation.VerificationMinMaxValue(item_status, 0, 6))
            Utils.ShowEnd(context, -1);

        /* 添加到数据库 */
        if (item_id > 0)
        {
            DbParameter[] param = { 
                DBHelper.MakeInParam("@Item_Id",(DbType)SqlDbType.Int,4,item_id),
                DBHelper.MakeInParam("@Item_Typ",(DbType)SqlDbType.TinyInt,1,item_typ),
                DBHelper.MakeInParam("@Item_Status",(DbType)SqlDbType.TinyInt,1,item_status),
            };
            int status = Convert.ToInt16(DBHelper.ExecuteScalar(CommandType.StoredProcedure, "Approved_Item", param));
            Utils.ShowEnd(context, status);
        }
        Utils.ShowEnd(context, -6);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}